package com.swjd.controller;

import com.swjd.domain.Comment;
import com.swjd.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommentController {
    @Autowired
    private CommentService commentService;

    /*
    查询
     */
    @GetMapping("/find/{id}")
    public Comment findById(@PathVariable("id") Integer id) {
        Comment byId = commentService.findById(id);
        return byId;
    }

    /*
    更新
     */
    @GetMapping("/update/{id}/{author}")
    public Comment update(@PathVariable("id") Integer id,@PathVariable("author") String author) {
        Comment byId = commentService.findById(id);
        byId.setAuthor(author);
        Comment comment1 = commentService.updateComment(byId);
        return comment1;
    }
    /*
    删除
     */
    @GetMapping("/delete/{id}")
    public void delete(@PathVariable("id") Integer id){
        commentService.deleteById(id);
    }
}
